<?php

class EmailController extends Controller
{
	public static function sendShiftChangeNotification($toUser,$status,$shiftChange)
	{
	
		$userModel = User::model()->findByPk($toUser);
		
		if($userModel == null) {
			return false;
		}
		
		$newStatus = ShiftChange::getStatus($status);
		
		$content = "<font color=blue><b><h1> STAFFer Shift Change Status Notification </h1></b></font>
					<font color=black><b> Hello".$userModel->fullname.", <br><br> The status of one of your opened Shift Change requests has changed to <span style='color:red;font-weight:bold;'>"
					.$newStatus.
					"</span></b>
					<br><br>
					To see it, click"
					. CHtml::link(CHtml::encode('here'), array('http://10.198.28.163/staffer/index.php/shiftChange', 'id'=>$shiftChange)) .					
					"</font>
					<h5> Please don't reply to this email... cuz no one will read it :-P</h5>
					";
								
		// Plain text content
		$plainTextContent = "STAFFer Shift Change Status Notification \n
							 \n
							 Hello ".$userModel->fullname.", \n
							 The status of one of your Shift Change requests has changed to \"".$newStatus."\"\n
							 \n
							 Please visit the STAFFer tool and go to \"Shifts/Shift Change Management\" for more details \n
							 \n
							 Please don't reply to this email... cuz no one will read it :-P";
		
		// Get mailer
		$SM = Yii::app()->swiftMailer;								
		
		// Get config
		$mailHost = 'smtp.gmail.com';
		$mailPort = 465; // Optional

		// New transport
		$Transport = $SM->smtpTransport($mailHost, $mailPort);
	 
		// Mailer
		$Mailer = $SM->mailer($Transport);
	 
		// New message
		$Message = $SM
			->newMessage('STAFFer Notification')
			->setFrom(array('cr.tac.staffer@gmail.com' => 'CR-TAC STAFFer'))
			->setTo(array($userModel->email => $userModel->fullname))	
			->addPart($content, 'text/html')
			->setBody($plainTextContent);
	 
		// Send mail
		$result = $Mailer->send($Message);		
		
		return $result;
		
		//$this->render('index');
	}
	
	public function sendSwapNotification($toUser,$status,$shiftChange)
	{
	
		$userModel = User::model()->findByPk($toUser);
		
		if($userModel == null) {
			return false;
		}
		
		$newStatus = ShiftChange::getStatus($status);
		
		$content = "<font color=blue><b><h1> STAFFer Q-Shift SWAP Status Notification </h1></b></font>
					<font color=black><b> Hello".$userModel->fullname.", <br><br> The status of one of your opened Q-Shift SWAPs has changed to <span style='color:red;font-weight:bold;'>"
					.$newStatus.
					"</span></b>
					<br><br>
					To see it, click "
					. CHtml::link(CHtml::encode('here'), array('http://10.198.28.163/staffer/index.php/shiftChange', 'id'=>$shiftChange)) .					
					"</font><br>
					<h5> Please don't reply to this email... cuz no one will read it :-P</h5>
					";
								
		// Plain text content
		$plainTextContent = "STAFFer Q-Shift SWAP Status Notification \n
							 \n
							 Hello ".$userModel->fullname.", \n
							 The status of one of your Shift Change requests has changed to \"".$newStatus."\"\n
							 \n
							 Please visit the STAFFer tool and go to \"Q-Shifts/Swap Management\" for more details \n
							 \n
							 Please don't reply to this email... cuz no one will read it :-P";
		
		// Get mailer
		$SM = Yii::app()->swiftMailer;								
		
		// Get config
		$mailHost = 'smtp.gmail.com';
		$mailPort = 465; // Optional

		// New transport
		$Transport = $SM->smtpTransport($mailHost, $mailPort);
	 
		// Mailer
		$Mailer = $SM->mailer($Transport);
	 
		// New message
		$Message = $SM
			->newMessage('STAFFer Notification')
			->setFrom(array('cr.tac.staffer@gmail.com' => 'CR-TAC STAFFer'))
			->setTo(array($userModel->email => $userModel->fullname))	
			->addPart($content, 'text/html')
			->setBody($plainTextContent);
	 
		// Send mail
		$result = $Mailer->send($Message);		
		
		return $result;
		
		//$this->render('index');
	}
	
}